﻿<template>
    <div v-cloak>
        <component is="style" />
        <van-popup v-model="show" position="bottom" :round="round" :style="{ height: height,maxHeight:maxHeight }" v-on:close="show=false" :close-on-click-overlay="closeOnClickOverlay" :closeable="closeable" class="hidden">
            <div class="flex-column hidden">
                <div v-if="!$slots.title" class="bg-light" style="text-align: center; padding: 16px 0 10px 0;position:sticky;">{{title}}</div>
                <slot name="title"></slot>
                <div class="flex-column-fill">
                    <slot></slot>
                </div>
            </div>
        </van-popup>
    </div>
</template>
<script>
    module = (function (hxt) {
        return {
            name: 'hxt.popup',
            props: {
                value: {
                    type: Boolean,
                    'default': function () {
                        return false;
                    }
                },
                height: {
                    type: String,
                    default: function () {
                        return 'auto';
                    }
                },
                maxHeight: {
                    type: String,
                    default: function () {
                        return '100%';
                    }
                },
                closeOnClickOverlay: {//是否在点击遮罩层后关闭
                    type: Boolean,
                    default: function () {
                        return false;
                    }
                },
                closeable: {//是否显示关闭图标
                    type: Boolean,
                    default: function () {
                        return false;
                    }
                },
                round: {// 	是否显示圆角
                    type: Boolean,
                    default: function () {
                        return false;
                    }
                },
                title: {//标题 如果插槽有内容，则title无效
                    type: String,
                    default: function () {
                        return '';
                    }

                }
            },
            data: function () {
                return {

                };
            },
            computed: {
                show: {
                    get: function () {
                        return this.value;
                    },
                    set: function (val) {
                        this.$emit('input', val);
                    }
                }
            },
            watch: {
                show: function (val) {
                    var _this = this;
                    hxt.popupAdapter.appWatch('hxt.popup.show', val, function () { _this.show = false; });
                },
            },
            activated: function () {

            },
            mounted: function () {
                //console.log(this.msg)
            },
            methods: {
                photoBrowser: function (MediaList, index) {
                    vant.ImagePreview({
                        images: MediaList.map(function (item) { return item.aKey }),
                        startPosition: index,
                        closeable: true,
                    });

                },
                playMedia: function (evt) {
                    var el = evt.currentTarget
                        , audios = $('audio')
                        , videos = $('video');
                    $.each(audios, function (idx, item) {
                        if (item !== el) {
                            item.pause();
                        }
                    });
                    $.each(videos, function (idx, item) {
                        if (item !== el) {
                            item.pause();
                        }
                    });
                },
                fileIco: function (url) { //wxs方法
                    var ico = 'fa fa-file-o';
                    if (!!url) {
                        var index = url.lastIndexOf('.');
                        if (index > -1) {
                            var str = url.substring(index + 1).toLowerCase();
                            switch (str) {
                                case 'doc':
                                case 'docx':
                                    ico = 'fa fa-file-word-o';
                                    break;
                                case 'xls':
                                case 'xlsx':
                                    ico = 'fa fa-file-excel-o';
                                    break;
                                case 'ppt':
                                case 'pptx':
                                    ico = 'fa fa-file-powerpoint-o';
                                    break;
                                case 'pdf':
                                    ico = 'fa fa-file-pdf-o';
                                    break;
                            }
                        }
                    }
                    return ico;
                },
                open: function (obj) {
                    window.open(obj.aKey);
                    return;
                    wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
                        wx.updateAppMessageShareData({
                            title: '文件', // 分享标题
                            desc: obj.aDesc, // 分享描述
                            link: obj.aKey, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                            imgUrl: '', // 分享图标
                            success: function () {
                                // 设置成功
                                hxt.alert(JSON.stringify(res), '分享');
                            },
                            fail: function (err) {
                                hxt.alert(JSON.stringify(err), '分享失败');
                            }
                        })
                    });
                },
            },
            components: {

            }
        };
    })(window.$jscript.fn);
</script>
<style>
</style>